package com.sf.fy.uav.common.utils;

import java.util.function.Supplier;

/**
 * 请求响应编码
 *
 * @Author LTQ
 */
public interface ResultCode {

    /**
     * 成功
     */
    ResultCode SUCCESS = build(() -> Const.RESULT_CODE_SUCCESS);

    /**
     * 失败
     */
    ResultCode FAIL = build(() -> Const.RESULT_CODE_FAIL);

    /**
     * 异常
     */
    ResultCode ERROR = build(() -> Const.RESULT_CODE_SERVICE_ERROR);

    /**
     * 响应码
     *
     * @return
     */
    default Integer getCode() {
        return Const.RESULT_CODE_SERVICE_ERROR;
    }

    /**
     * 构建方法
     *
     * @param code
     * @return
     */
    static ResultCode build(Supplier<Integer> code) {
        return new ResultCode() {
            @Override
            public Integer getCode() {
                return code.get();
            }
        };
    }

    final class Const {
        public static final Integer RESULT_CODE_SUCCESS = 200;

        public static final Integer RESULT_CODE_FAIL = 40000;

        public static final Integer RESULT_CODE_SERVICE_ERROR = -1;
    }

}
